<?php

namespace App\Http\Middleware;

use Closure;
use Jinxing\Admin\Traits\ExceptTrait;
use App\Repositories\Statistical\UserRepository;

class StatisticsMain
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // 没有登录
        if (empty(session('user')) || empty(session('user.user_id'))) {
            return redirect('statistical/index/login');
        }

        // 主账号才有权限
        if (session('user.type') != UserRepository::TYPE_MAIN) {
            return redirect('statistical/index/index');
        }

        return $next($request);
    }
}
